package dryven.model.binding.form;

import dryven.model.binding.fieldset.Field;
import dryven.model.binding.fieldset.Field.Access;
import dryven.model.validation.ErrorMessage;
import dryven.model.validation.Validator;
import dryven.util.crypt.SHA1Hash;
import dryven.util.json.dryvenjson.JSON;
import dryven.view.Formatter;

public class FormBinding {
	private Field _field;
	private Form _form;
	
	public FormBinding(Field field, Form form) {
		super();
		_field = field;
		_form = form;
	}
	
	@JSON
	public Access getAccess() {
		return _field.getAccess();
	}
	public Class<? extends Formatter> getFormatterClass() {
		return _field.getFormatterClass();
	}
	@JSON
	public int getMaxLength() {
		return _field.getMaxLength();
	}
	@JSON
	public String getName() {
		return _field.getUniqueName();
	}
	public Class<? extends Validator> getValidatorClass() {
		return _field.getValidatorClass();
	}
	@JSON
	public Object getValue() {
		return _form.getFieldValue(_field);
	}
	@JSON
	public String getError() {
		ErrorMessage msg = _form.getFieldError(_field);
		if(msg!=null) {
			return msg.toString();
		}
		return null;
	}
	public Class<?> getValueType() {
		return _field.getValueType();
	}
	@JSON
	public String getViewComponentClass() {
		return _field.getViewComponentClass();
	}
	@JSON
	public boolean isRequired() {
		return _field.isRequired();
	}
}
